{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "aa103ad5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "200\n",
      "{'request_id': '1678938822,ad143a62-0047-4ec8-928f-f6fa9df1e46b', 'time_used': 227, 'faces': [{'face_token': '1730a33ed1e029f97e10094a91c8ee9a', 'face_rectangle': {'top': 493, 'left': 221, 'width': 549, 'height': 549}}], 'image_id': 'jbpGjNGyeKd5+IcaMIW1LA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\n",
    "    \"image_base64\":img,\n",
    "          \"api_key\":\"WlGS-s9eSvO6Tsi-M2vdlPPPlkys2VI7\",\n",
    "          \"api_secret\":\"byncSCLcp9xvKcke_gOqtDU1VDnciN5w\"\n",
    "}\n",
    "\n",
    "request_url = request_url\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "\n",
    "print(response.status_code)\n",
    "print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4ec02d54",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1679212887,315ba888-b366-446c-99a1-ba402a956599', 'time_used': 303, 'faces': [{'face_token': 'c5fd2a011674eef0cb1fb47ccb7a43af', 'face_rectangle': {'top': 493, 'left': 221, 'width': 549, 'height': 549}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 20}, 'smile': {'value': 6.255, 'threshold': 50.0}, 'headpose': {'pitch_angle': 26.062857, 'roll_angle': -1.0754629, 'yaw_angle': -5.569904}, 'blur': {'blurness': {'value': 0.372, 'threshold': 50.0}, 'motionblur': {'value': 0.372, 'threshold': 50.0}, 'gaussianblur': {'value': 0.372, 'threshold': 50.0}}, 'emotion': {'anger': 0.001, 'disgust': 0.001, 'fear': 0.001, 'happiness': 0.046, 'neutral': 99.132, 'sadness': 0.047, 'surprise': 0.772}, 'facequality': {'value': 26.22, 'threshold': 70.1}, 'beauty': {'male_score': 82.755, 'female_score': 85.456}}}], 'image_id': 'jbpGjNGyeKd5+IcaMIW1LA==', 'face_num': 1}\n",
      "200\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++ 人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('1.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "payload = {\n",
    "    'image_base64':img,\n",
    "    \"api_key\":\"dcRIuK-sU-SVBsIe_w7cWHUL5cgH8RJ6\",\n",
    "    \"api_secret\":\"1OfAAMc32wL2E4LsMwJN28bfEhjFiZEy\",\n",
    "    'return_attributes':'gender,age,smiling,headpose,facequality,emotion,blur,beauty'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data = payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d78f68ff",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
